package cbbx_sm.parser;

import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import cbbx_sm.utils.ExperimentManager;
import cbbx_sm.utils.Timestamp;

/**
 * This class contains the bounding box data parsed from one file
 * regarding one camera for a certain amount of time.
 * 
 * @author Alessio
 *
 */
public class CameraData {
	private String cameraId;
	private String imageFile;
	private List<Frame> frames;
	
	public CameraData(String cameraId){
		this.cameraId = cameraId;
	}
	
	public Timestamp getInitialTimestamp(){
		if (frames != null && frames.get(0) != null)
			return frames.get(0).getTimestamp();
		return null;
	}
	
	public Timestamp getFinalTimestamp(){
		if (frames != null && frames.size() > 0 && frames.get(frames.size() - 1) != null)
			return frames.get(frames.size() - 1).getTimestamp();
		return null;
	}
	
	public int getNumberOfFrameWithBoundingBoxes(){
		int counter = 0;
		
		for (Frame f : frames)
			if (f.getEntities().size() > 0)
				counter++;
		
		return counter;
	}
	
	public Set<BoundingBox> getAllBoundingBoxes(){
		Set<BoundingBox> boxes = new HashSet<BoundingBox>();
		for (Frame f : frames)
			for (Entity e : f.getEntities())
				boxes.add(e.getBoxes()[ExperimentManager.boxLocationId]);
		return boxes;
	}
	
	// Getters & Setters
	
	public String getCameraId() {
		return cameraId;
	}
		
	public List<Frame> getFrames() {
		return frames;
	}
	
	public void setFrames(List<Frame> frames) {
		this.frames = frames;
		Collections.sort(this.frames);
	}
	
	public void setImageFile(String imageFile) {
		this.imageFile = imageFile;
	}

	public String getImageFile() {
		return imageFile;
	}
}
